<!-- 商城分类 -->
<template>
	<!-- #ifdef MP-WEIXIN -->
	<view class="content" :style="{top:fixedTop + 'px'}">
		<!-- #endif -->
		<!-- #ifndef MP-WEIXIN -->
		<view class="content">
			<!-- #endif -->
			<!-- <scroll-view></scroll-view> -->
			<scroll-view scroll-y class="left-aside">
				<view v-for="item in categoryList" :key="item.id" class="f-item b-b" :class="{active: item.id === currentId}"
				 @click="tabtap(item)">
					{{item.cate_name}}
				</view>
			</scroll-view>
			<!-- :scroll-top="tabScrollTop" -->
			<!-- -->
			<scroll-view scroll-with-animation scroll-y class="right-aside" @scroll="asideScroll" :scroll-into-view="scrollIdIn ? scrollIdIn : scrollId">
				<!-- :id="'main-'+item.id" -->
				<block v-for="(item,index) in categoryList" :key="item.id">
					<view class="s-list" :id="'main-'+item.id">
						<view class="carousel-section" v-if="index == 0&&categoryBanner.length">
							<swiper class="carousel" circular :indicator-dots="true" indicator-color="rgba(255,255,255,.5)"
							 indicator-active-color="#ffffff">
								<swiper-item v-for="(ite, inde) in categoryBanner" :key="inde" class="carousel-item" @click="navTo(ite.url)">
									<image class="carousel-image" lazy-load :src="ite.pic" />
								</swiper-item>
							</swiper>
						</view>
						<text class="s-item">{{item.cate_name}}</text>
						<view class="t-list">
							<block v-for="titem in item.children" :key="titem.id">
								<view @click="navToList(titem.id,titem.cate_name)" class="t-item">
									<image class="t-item-img" :src="titem.pic"></image>
									<text class="t-item-text">{{titem.cate_name}}</text>
								</view>
							</block>
						</view>
					</view>
				</block>

			</scroll-view>
		</view>
</template>

<script>
	import {
		getCategory
	} from '@/api/mall.js'
	export default {
		data() {
			return {
				// #ifdef MP-WEIXIN
				fixedTop: getApp().globalData.MenuButtonTop + 38,
				// #endif
				tabScrollTop: 0,
				currentId: 0,
				flist: [],
				slist: [],
				tlist: [],
				categoryList: [],
				scrollIdIn: '',
				scrollId: "",
				categoryBanner: []
			}
		},
		created() {
			getCategory().then(res => {
				this.categoryList = res.data;
				this.currentId = res.data[0].id;
				this.scrollId = `main-${res.data[0].id}`;
			})
			this.categoryBanner = uni.getStorageSync("categoryBanner")
		},
		methods: {
			asideScroll(e) { //不能删
			},
			// 点击banner跳转
			navTo(url) {
				uni.navigateTo({
					url:url
				})
			},
			//一级分类点击
			tabtap(item) {
				this.currentId = item.id;
				this.scrollIdIn = `main-${item.id}`;
			},
			//二级点击
			navToList(id, name) {
				uni.navigateTo({
					url: '/mall/cate/list?id=' + id + '&name=' + name
				})
			}
		}
	}
</script>

<style lang='scss' scoped>
	/* .content- */
	.content {
		position: fixed;
		/* #ifdef APP-PLUS */
		top: calc(44px + var(--status-bar-height));
		/* #endif */
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		bottom: 100rpx;
		bottom: calc(100rpx + env(safe-area-inset-bottom));
		display: flex;
	}

	.left-aside {
		flex-shrink: 0;
		width: 200rpx;
		height: 100%;
		background-color: #fff;
	}

	.f-item {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		padding: 0 10rpx;
		box-sizing: border-box;
		height: 100rpx;
		font-size: 28rpx;
		text-align: center;
		color: $mall-color-base;
		position: relative;

		&.active {
			color: #fb3737;
			background: #f8f8f8;

			&:before {
				content: '';
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				height: 36rpx;
				width: 8rpx;
				background-color: #fb3737;
				border-radius: 0 4px 4px 0;
				opacity: .8;
			}
		}
	}

	.right-aside {
		flex: 1;
		overflow: hidden;
		padding: 20rpx;
		.carousel-section{
			width: 510rpx;
			height: 150rpx;
			.carousel{
				width: 100%;
				height: 100%;
				.carousel-image{
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.s-item {
		display: flex;
		align-items: center;
		height: 92rpx;
		padding-top: 8rpx;
		font-size: 28rpx;
		color: $font-color-dark;
	}

	.t-list {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		background: #fff;
		padding-top: 12rpx;

		&:after {
			content: '';
			flex: 99;
			height: 0;
		}
	}

	.t-item {
		flex-shrink: 0;
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 170rpx;
		font-size: 26rpx;
		color: #666;
		padding-bottom: 20rpx;

		.t-item-img {
			width: 120rpx;
			height: 120rpx;
		}
		.t-item-text{
			text-align: center;
			margin-top: 4rpx;
			width: 120rpx;
			font-size: 24rpx;
		}
	}
</style>
